package com.baiyue.controller;


import com.baiyue.annotation.SystemLog;
import com.baiyue.entity.Charging;
import com.baiyue.enums.LogType;
import com.baiyue.model.MoneyResult;
import com.baiyue.model.charging.ChargingDataRequest;
import com.baiyue.model.charging.ChargingDataResponse;
import com.baiyue.result.Result;
import com.baiyue.service.ChargingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *
 * @author 伍波
 * @date 2024-05-22
 */
@RestController
@RequestMapping("/api/charging")
public class ChargingController {
    @Autowired
    private ChargingService chargingService;

    @SystemLog(description = "开启计费",type = LogType.OPEN)
    @PostMapping("/invoicing")
    public Result<Boolean> insertCharging(@RequestBody ChargingDataRequest request) {
        chargingService.insert(request);
        return Result.success(true);
    }

    @PostMapping("/byUuids")
    public Result<List<ChargingDataResponse>> getChargingData(@RequestBody ChargingDataRequest request) {
        return Result.success(chargingService.findByUuid(request));
    }

    @SystemLog(description = "暂停计费",type = LogType.SUSPEND)
    @PostMapping("/pause")
    public Result<Boolean> pause(@RequestBody ChargingDataRequest request){
        chargingService.pauseByUuid(request);
        return Result.success(true);
    }

    @SystemLog(description = "恢复计费",type = LogType.RESUME)
    @PostMapping("/recovery")
    public Result<Boolean> recovery(@RequestBody ChargingDataRequest request) {
        chargingService.recovery(request);
        return Result.success(true);
    }

    @PostMapping("/getMoney")
    public Result<MoneyResult> getMoney(@RequestBody ChargingDataRequest request) {
        return Result.success(chargingService.getMoney(request));
    }

    @SystemLog(description = "取消订单",type = LogType.CANCEL)
    @PostMapping("/cancel")
    public Result<Boolean> cancelOrder(@RequestBody ChargingDataRequest request){
        chargingService.cancelOrder(request);
        return Result.success(true);
    }

    @SystemLog(description = "更新计费信息",type = LogType.UPDATE)
    @PostMapping("/update")
    public Result<Boolean> updateChargingAndTableSet(@RequestBody ChargingDataRequest request) {
        chargingService.updateChargingAndTableSet(request);
        return Result.success(true);
    }
}

